# 构建阶段
FROM node:18.19.1-alpine3.19 AS builder

WORKDIR /app

# 安装依赖
COPY package.json package-lock.json* ./
RUN npm ci

# 拷贝源代码
COPY . .

# 构建应用
RUN npm run build

# 运行阶段
FROM node:18.19.1-alpine3.19

WORKDIR /app

# 安装生产依赖
COPY package.json package-lock.json* ./
RUN npm ci --only=production

# 从构建阶段拷贝构建文件
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./

# 设置环境变量
ENV NODE_ENV=production
ENV PORT=3000

# 暴露端口
EXPOSE 3000

# 启动应用
CMD ["npm", "run", "start"] 